package com.tanhua.model.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class QuestionUserLock extends BasePojo implements Serializable {

    private long id;
    private long userId;
    private long questionnaireId;
    private long isLock;

    /**
     * @param length          保存记录条数
     * @param userId          用户id
     * @param questionnaireId 试卷id
     * @return
     */
    public static List<QuestionUserLock> init(int length, Long userId, long questionnaireId) {
        List<QuestionUserLock> lockList = new ArrayList<>(length);
        for (int i = 0; i < length; i++) {
            //保存至lock表 三条记录
            QuestionUserLock lock = new QuestionUserLock();
            lock.setUserId(userId);
            lock.setQuestionnaireId(questionnaireId + i);
            //（0解锁，1锁住）
            if (i == 2) {
                //试卷为1时 其他两个都会锁住
                lock.setIsLock(1);
            }
            lockList.add(lock);
        }
        return lockList;
    }

}